package model.factories.misc;

import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;
import model.Interpreter;
import model.SyntaxErrorException;
import model.commands.Command;
import model.commands.misc.VariableCommand;
import model.factories.CommandFactory;


/**
 * A factory used to build LiteralCommands with the value of scoped variables
 * 
 * @author Erick Gonzalez
 * @author JLongley
 */
public class VariableCommandFactory extends CommandFactory {
    /**
     * Pattern that matches variables.
     */
    public static final Pattern VARIABLE_PATTERN = Pattern.compile(":[a-zA-z]+");

    /**
     * 
     * @param interpreter an Interpreter
     */
    public VariableCommandFactory (Interpreter interpreter) {
        super(interpreter);
    }

    @Override
    public Command createCommand (Scanner commandReader,
                                  Map<String, Integer> variables) throws SyntaxErrorException {
        String varName = commandReader.next();
        return new VariableCommand(variables, varName);
    }

    @Override
    public Pattern patternToMatch () {
        return VARIABLE_PATTERN;
    }
}
